home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Libraries / VideoToolbox 96.06.15 / VideoToolboxSources / ChooseScreen.c < prev    next >
Text File  |  1995-01-07  |  2KB  |  75 lines

  1. /*
  2. ChooseScreen.c
  3.  
  4. Displays a screen number on every screen, and accepts the typed selection from
  5. the user, using the argument value as the default. No check is made for
  6. validity of the default or the reply.
  7.     screen=1;
  8.     screen=ChooseScreen(screen,"Which screen?");
  9.  
  10. HISTORY:
  11. 9/5/94 dgp removed assumption in printf's that int==short.
  12. 10/2/94 dgp added question argument.
  13. 1/5/95    dgp made compatible with Universal Headers 2.
  14. */
  15. #include "VideoToolbox.h"
  16. #if UNIVERSAL_HEADERS
  17.     #include <LowMem.h>
  18. #else
  19.     extern void LMSetGhostWindow(WindowPeek GhostWindowValue);
  20.     #define LMSetGhostWindow(GhostWindowValue) ((* (WindowPeek *) 0x0A84) = (GhostWindowValue))
  21. #endif
  22.  
  23. int ChooseScreen(int screen,const char *question)
  24. {
  25.     short i,fontNumber,textSize;
  26.     Rect r;
  27.     GDHandle device=NULL,oldDevice=NULL;
  28.     WindowPtr window=NULL,oldWindow=NULL,windows[MAX_SCREENS];
  29.     unsigned char string[16]="\p0";
  30.     char str[32];
  31.     FontInfo fontInfo;
  32.     long ticks;
  33.  
  34.     oldDevice=GetGDevice();
  35.     SetGDevice(GetMainDevice());
  36.     GetPort(&oldWindow);
  37.     ticks=TickCount();
  38.     for(i=0;i<MAX_SCREENS;i++){
  39.         device=GetScreenDevice(i);
  40.         if(device == NULL)break;
  41.         SetRect(&r,0,0,160,160);
  42.         CenterRectInRect(&r,&(*device)->gdRect);
  43.         string[1]='0'+i;
  44.         windows[i]=NewWindow(NULL,&r,string,TRUE,plainDBox,(WindowPtr) -1L,0,0);
  45.         SetPort(windows[i]);
  46.         if(i==0)GetFNum("\pChicago",&fontNumber);
  47.         TextFont(fontNumber);
  48.         textSize=128;
  49.         TextSize(textSize);
  50.         if(i==0)GetFontInfo(&fontInfo);
  51.         SetRect(&r,0,0,StringWidth(string),fontInfo.ascent);
  52.         CenterRectInRect(&r,&windows[i]->portRect);
  53.         MoveTo(r.left,r.bottom);
  54.         DrawString(string);
  55.     }
  56.     #if UNIVERSAL_HEADERS>1
  57.         LMSetGhostWindow((WindowRef)windows[0]);    // doesn't work; don't know why.
  58.     #else
  59.         LMSetGhostWindow((WindowPeek)windows[0]);    // doesn't work; don't know why.
  60.     #endif
  61.     SetPort(oldWindow);
  62.     SetGDevice(oldDevice);
  63.     ticks=ticks+50-TickCount();
  64.     if(ticks>0)Delay(ticks,&ticks);
  65.     printf("%s (%d):",question,screen);
  66.     gets(str);
  67.     sscanf(str,"%d",&screen);
  68.     for(i=0;i<MAX_SCREENS;i++){
  69.         device=GetScreenDevice(i);
  70.         if(device==NULL)break;
  71.         DisposeWindow(windows[i]);
  72.     }
  73.     return screen;
  74. }
  75.